<tagLib name="html" />

<div id="answer-container" class="container">
    <div id="msg-container">
        <h2 class="error-tips"></h2>
    </div>
    <h2><a href="{$question.question_id|format_question_url=$question['title']}">{$question.title}</a></h2>
    <div id="revision-container">
    <p>{$Think.lang.revision_tips}</p>
    <notempty name="revisions">
    <p>
    	<label for="revision">{$Think.lang.revision}:</label>
    	<select id="revision" onchange="loadAnswerRevision(this,'answer-details');" style="width:300px">
    		<volist name="revisions" id="vo">
    		<option value="{$vo.id}">{$Think.lang.revision} {:count($revisions)-$key}: {$Think.lang.edited_by} {$vo.editor_name} {$vo.create_time|pretty_date}</option>
    		</volist>
    	</select>
    </p>
    </notempty>
    </div>
    <form id="answer-form" action="{:U('Answer/edit')}" method="POST">
        <p><html:markitup id="answer-details" name="details" content="{$answer.details}" /></p>
        <p id="answer-counter" class="counter"></p>
        <eq name="answer.poster_id" value="$_user.user_id">
        <p><input id="new-comment-alert" type="checkbox" name="new_comment_alert" value="1" <eq name="answer.new_comment_alert" value="1">checked</eq> /> <label for="new-comment-alert">{$Think.lang.new_comment_alert}</label></p>
        </eq>
        <eq name="captcha" value="1">
        <div class="captcha-container">
            <label for="verify">{$Think.lang.captcha}:</label><input id="verify" class="verify" type="text" name="verify" value="" />
            <img class="captcha" src="{:U('Ajax/captcha')}" title="{$Think.lang.captcha_again}" onclick="reCaptcha(this);" />
        </div>
        </eq>
        <p><input id="answer-submit" class="button" type="button" value="{$Think.lang.save_edit}" /></p>
    </form>
</div>

<script type="text/javascript">
$(function(){

    var maxChars = {$_global.max_post_chars};
    
    $('#answer-details').artTxtCount($('#answer-counter'), maxChars);

    $('#answer-submit').click(function(){
        var url = $('#answer-form').attr('action');
        var redirect = $(location).attr('href');
        var newCommentAlert = $('#new-comment-alert').attr('checked') ? 1 : 0;
        var data = {
            new_comment_alert: newCommentAlert,
            aid: '{$answer.answer_id}',
            verify: $('#verify').val(),
            details: $('#answer-details').val()
        };
        $.post(url, data, function(json){
            $('#msg-container').show();
            var json = eval('('+json+')');
            if(json.status == 0){
                $('#msg-container>h2').html(json.info);
                return false;
            }else{
                $('#msg-container>h2').attr('class','success-tips').html(json.info);
                $('#answer-submit').attr({disabled:true, class:'alt-button'});
                setTimeout(function(){
                    window.location.href = redirect;
                }, WAIT_TIME);
            }
        });
    })
});
</script>
